<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Bomberman:  Fichier source de /home/ph3w/Bureau/lif7-bomberman/debug_memory.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Généré par Doxygen 1.7.1 -->
<script type="text/javascript">
function hasClass(ele,cls) {
  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
  if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
  if (hasClass(ele,cls)) {
    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}

function toggleVisibility(linkObj) {
 var base = linkObj.getAttribute('id');
 var summary = document.getElementById(base + '-summary');
 var content = document.getElementById(base + '-content');
 var trigger = document.getElementById(base + '-trigger');
 if ( hasClass(linkObj,'closed') ) {
   summary.style.display = 'none';
   content.style.display = 'block';
   trigger.src = 'open.png';
   removeClass(linkObj,'closed');
   addClass(linkObj,'opened');
 } else if ( hasClass(linkObj,'opened') ) {
   summary.style.display = 'block';
   content.style.display = 'none';
   trigger.src = 'closed.png';
   removeClass(linkObj,'opened');
   addClass(linkObj,'closed');
 }
 return false;
}
</script>
<div class="header">
  <div class="headertitle">
<h1>/home/ph3w/Bureau/lif7-bomberman/debug_memory.cpp</h1>  </div>
</div>
<div class="contents">
<a href="debug__memory_8cpp.html">Aller à la documentation de ce fichier.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;<a class="code" href="debug__memory_8h.html">debug_memory.h</a>&quot;</span>
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 <span class="comment">// NOTE A MOI MÊME : NE PAS OUBLIER D&#39;INITIALISER CETTE SALTE DE MEMBRE STATIC AINSI !!! ( principe singleton )</span>
<a name="l00004"></a>00004 <a class="code" href="class_c_memory_manager.html" title="Système de vérification de fuite mémoire.">CMemoryManager</a> <a class="code" href="class_c_memory_manager.html#a48a8bd38d884d860ba2482b1cff0e135" title="L&amp;#39;instance de la class.">CMemoryManager::c_inst</a>;
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 
<a name="l00007"></a>00007 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00008"></a>00008 <span class="comment">* @fn CMemoryManager::CMemoryManager()</span>
<a name="l00009"></a>00009 <span class="comment">* @brief Le constructeur par défaut.</span>
<a name="l00010"></a>00010 <span class="comment">* @note Initialise uniquement l&#39;ouverture du fichier de rapport</span>
<a name="l00011"></a>00011 <span class="comment">*/</span>
<a name="l00012"></a><a class="code" href="class_c_memory_manager.html#a348ff8aeb43bb768c0425f578c9f2480">00012</a> <a class="code" href="class_c_memory_manager.html#a348ff8aeb43bb768c0425f578c9f2480" title="Le constructeur par défaut.">CMemoryManager::CMemoryManager</a>()
<a name="l00013"></a>00013 {
<a name="l00014"></a>00014     <span class="keywordflow">if</span>( !(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a> = fopen(<span class="stringliteral">&quot;allocations.txt&quot;</span>,<span class="stringliteral">&quot;w&quot;</span>)) )
<a name="l00015"></a>00015         stdErrorE(<span class="stringliteral">&quot;Impossible d&#39;ouvrir le fichier &lt;allocations.txt&gt;&quot;</span>);
<a name="l00016"></a>00016 }
<a name="l00017"></a>00017 
<a name="l00018"></a>00018 
<a name="l00019"></a>00019 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00020"></a>00020 <span class="comment">* @fn CMemoryManager::~CMemoryManager()</span>
<a name="l00021"></a>00021 <span class="comment">* @brief Le desconstructeur par défaut</span>
<a name="l00022"></a>00022 <span class="comment">*</span>
<a name="l00023"></a>00023 <span class="comment">* C&#39;est ici que l&#39;on :</span>
<a name="l00024"></a>00024 <span class="comment">*   - détermine s&#39;il y a une fuite mémoire.</span>
<a name="l00025"></a>00025 <span class="comment">*   - construit la fin de rapport.</span>
<a name="l00026"></a>00026 <span class="comment">*/</span>
<a name="l00027"></a><a class="code" href="class_c_memory_manager.html#a2e609b1276459d743cfb91669007eee2">00027</a> <a class="code" href="class_c_memory_manager.html#a2e609b1276459d743cfb91669007eee2" title="Le desconstructeur par défaut.">CMemoryManager::~CMemoryManager</a>()
<a name="l00028"></a>00028 {
<a name="l00029"></a>00029     <span class="keywordflow">if</span>( <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.empty() ){<span class="comment">// Aucune fuite, bravo !</span>
<a name="l00030"></a>00030         fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;No leak detected, congratulations !\n&quot;</span>);
<a name="l00031"></a>00031     }<span class="keywordflow">else</span>{<span class="comment">// Fuites mémoires =(</span>
<a name="l00032"></a>00032         fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;Oops... Some leaks have been detected\n&quot;</span>);
<a name="l00033"></a>00033         <span class="comment">// Création du rapport</span>
<a name="l00034"></a>00034         <span class="comment">// Détail des fuites</span>
<a name="l00035"></a>00035         std::size_t totalSize = 0;
<a name="l00036"></a>00036         <span class="keywordflow">for</span>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i != <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.size(); i++ )
<a name="l00037"></a>00037         {
<a name="l00038"></a>00038             <span class="comment">// Ajout de la taille du bloc au cumul</span>
<a name="l00039"></a>00039             totalSize += <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].size;
<a name="l00040"></a>00040 
<a name="l00041"></a>00041             <span class="keywordflow">switch</span>( <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].type )
<a name="l00042"></a>00042             {
<a name="l00043"></a>00043                 <span class="keywordflow">case</span> <a class="code" href="class_c_memory_manager.html#ab8c28bbacbf41e539dcb0d1185588f99aa32ed10d616a4e916ec2f4abb3addfc7">__classic__</a>: {
<a name="l00044"></a>00044                     <span class="comment">// Inscription dans le fichier des informations sur le bloc courant</span>
<a name="l00045"></a>00045                     fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;Pointeur -&gt; 0x%08X | %15d octets | %15s | %u\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].ptr, static_cast&lt;int&gt;(<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].size), <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].fileName.c_str(), <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].line);
<a name="l00046"></a>00046                     <span class="comment">// Libération de la mémoire</span>
<a name="l00047"></a>00047                     <span class="comment">//free(c_Blocks[i].ptr);</span>
<a name="l00048"></a>00048                     <span class="keywordflow">break</span>;
<a name="l00049"></a>00049                 }
<a name="l00050"></a>00050                 <span class="keywordflow">case</span> <a class="code" href="class_c_memory_manager.html#ab8c28bbacbf41e539dcb0d1185588f99a9b94b817a58d40cd639aa7325ee2d42c">__SDL_Surface__</a>: {
<a name="l00051"></a>00051                     <span class="comment">// Inscription dans le fichier des informations sur le bloc courant</span>
<a name="l00052"></a>00052                     fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;Surface  -&gt; 0x%08X | %15d octets | %15s | %u\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].ptr, static_cast&lt;int&gt;(<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].size), <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].fileName.c_str(), <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].line);
<a name="l00053"></a>00053                     <span class="comment">// Libération de la mémoire</span>
<a name="l00054"></a>00054                     <span class="comment">//SDL_FreeSurface(c_Blocks[i].ptr);</span>
<a name="l00055"></a>00055                     <span class="keywordflow">break</span>;
<a name="l00056"></a>00056                 }
<a name="l00057"></a>00057                 <span class="keywordflow">case</span> <a class="code" href="class_c_memory_manager.html#ab8c28bbacbf41e539dcb0d1185588f99aa48ce3cc6f7b50a9267bdcedd9f648f2">__SDL_Font__</a>: {
<a name="l00058"></a>00058                     <span class="comment">// Inscription dans le fichier des informations sur le bloc courant</span>
<a name="l00059"></a>00059                     fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;TTF_Font -&gt; 0x%08X | %15d octets | %15s | %u\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].ptr, static_cast&lt;int&gt;(<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].size), <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].fileName.c_str(), <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].line);
<a name="l00060"></a>00060                     <span class="comment">// Libération de la mémoire</span>
<a name="l00061"></a>00061                     <span class="comment">//TTF_CloseFont(c_Blocks[i].ptr);</span>
<a name="l00062"></a>00062                     <span class="keywordflow">break</span>;
<a name="l00063"></a>00063                 }
<a name="l00064"></a>00064             }
<a name="l00065"></a>00065         }
<a name="l00066"></a>00066 
<a name="l00067"></a>00067         <span class="comment">// Affichage du cumul des fuites</span>
<a name="l00068"></a>00068         fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;-- %d blocs non-libéré(s), %d octets --\n&quot;</span>, static_cast&lt;int&gt;(<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.size()), static_cast&lt;int&gt;(totalSize));
<a name="l00069"></a>00069     }
<a name="l00070"></a>00070     time_t hold_time = time(NULL);
<a name="l00071"></a>00071     fprintf( <a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;Report dated: %s\n&quot;</span>, ctime(&amp;hold_time));
<a name="l00072"></a>00072     <span class="keywordflow">if</span>( <a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a> )
<a name="l00073"></a>00073         fclose(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>);
<a name="l00074"></a>00074 }
<a name="l00075"></a>00075 
<a name="l00076"></a>00076 
<a name="l00077"></a>00077 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00078"></a>00078 <span class="comment">* @fn void* CMemoryManager::allocate( size_t size, const char fileName[], unsigned int line, bool is_array )</span>
<a name="l00079"></a>00079 <span class="comment">* @brief Récolte les informations sur les allocations</span>
<a name="l00080"></a>00080 <span class="comment">*</span>
<a name="l00081"></a>00081 <span class="comment">* Permet grace aux surchages de new de compter et d&#39;identifier les allocations</span>
<a name="l00082"></a>00082 <span class="comment">*/</span>
<a name="l00083"></a>00083 <span class="comment">// Ajoute une allocation mémoire</span>
<a name="l00084"></a><a class="code" href="class_c_memory_manager.html#a72136456ec234a5abee8537160855a45">00084</a> <span class="keywordtype">void</span>* <a class="code" href="class_c_memory_manager.html#a72136456ec234a5abee8537160855a45" title="Récolte les informations sur les allocations.">CMemoryManager::allocate</a>( <span class="keywordtype">size_t</span> size, <span class="keyword">const</span> <span class="keywordtype">char</span> fileName[], <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> line, <span class="keywordtype">bool</span> is_array )
<a name="l00085"></a>00085 {
<a name="l00086"></a>00086     <span class="comment">// Allocation de la mémoire</span>
<a name="l00087"></a>00087     <span class="keywordtype">void</span>* ptr = malloc(size);
<a name="l00088"></a>00088 
<a name="l00089"></a>00089     <span class="comment">// Ajout du bloc à la liste des blocs alloués</span>
<a name="l00090"></a>00090     <a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html" title="Stock les info sur les block mémoires alloués.">s_AllocatatedBlock</a> newBlock;
<a name="l00091"></a>00091     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#afa806a065eca6cf997823dd160e6503c" title="Le pointeur.">ptr</a>        = ptr;
<a name="l00092"></a>00092     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#a66687bce2aeeb39d1066c878e37136b0" title="Taille allouée.">size</a>       = size;
<a name="l00093"></a>00093     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#a050ffa267c9f209f6a1159b6c2832142" title="Fichier contenant l&amp;#39;allocation.">fileName</a>   = fileName;
<a name="l00094"></a>00094     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#a04a808fd7b875bb64b2e712c5da7968c" title="Ligne de l&amp;#39;allocation.">line</a>       = line;
<a name="l00095"></a>00095     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#ad77e2f233ea15004acfd3206b00dc1dc" title="Type d&amp;#39;objet (SDL ou classic ?).">type</a>       = __classic__;
<a name="l00096"></a>00096     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#ae08523066b3c9def225d38452557750f" title="Est-ce un objet ou un tableau ?">is_array</a>   = is_array;
<a name="l00097"></a>00097     <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.push_back(newBlock);
<a name="l00098"></a>00098 
<a name="l00099"></a>00099 <span class="preprocessor">    #ifdef MEMORY_FULL_REPORT</span>
<a name="l00100"></a>00100 <span class="preprocessor"></span>        fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;++ Allocation                | 0x%08X | %15d octets | &lt;%15s&gt;:%u\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)ptr, static_cast&lt;int&gt;(size), fileName, line);
<a name="l00101"></a>00101 <span class="preprocessor">    #endif</span>
<a name="l00102"></a>00102 <span class="preprocessor"></span>    <span class="keywordflow">return</span> ptr;
<a name="l00103"></a>00103 }
<a name="l00104"></a>00104 
<a name="l00105"></a>00105 
<a name="l00106"></a>00106 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00107"></a>00107 <span class="comment">* @fn void CMemoryManager::Free( void* ptr, bool is_array )</span>
<a name="l00108"></a>00108 <span class="comment">* @brief Récolte les informations sur les désallocations</span>
<a name="l00109"></a>00109 <span class="comment">*</span>
<a name="l00110"></a>00110 <span class="comment">* Permet grace aux surchages de delete de compter et d&#39;identifier les désallocations.&lt;br /&gt;</span>
<a name="l00111"></a>00111 <span class="comment">* ( Retire une allocation mémoire )</span>
<a name="l00112"></a>00112 <span class="comment">*/</span>
<a name="l00113"></a><a class="code" href="class_c_memory_manager.html#a05f473d76591319066c50dbc071c5be1">00113</a> <span class="keywordtype">void</span> <a class="code" href="class_c_memory_manager.html#a05f473d76591319066c50dbc071c5be1" title="Récolte les informations sur les désallocations.">CMemoryManager::Free</a>( <span class="keywordtype">void</span>* ptr, <span class="keywordtype">bool</span> is_array )
<a name="l00114"></a>00114 {
<a name="l00115"></a>00115     <span class="comment">// Recherche de l&#39;adresse dans les blocs alloués</span>
<a name="l00116"></a>00116     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0;
<a name="l00117"></a>00117     <span class="keywordflow">for</span>( i=0; i&lt;<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.size(); i++ )
<a name="l00118"></a>00118     {
<a name="l00119"></a>00119         <span class="keywordflow">if</span>( <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].ptr == ptr ) <span class="keywordflow">break</span>;
<a name="l00120"></a>00120     }
<a name="l00121"></a>00121 
<a name="l00122"></a>00122     <span class="comment">// Si le bloc n&#39;a pas été alloué, on génère une erreur</span>
<a name="l00123"></a>00123     <span class="keywordflow">if</span>( <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.size() &lt;= i )
<a name="l00124"></a>00124     {
<a name="l00125"></a>00125         <span class="comment">// En fait ça arrive souvent, du fait que le delete surchargé</span>
<a name="l00126"></a>00126         <span class="comment">// est pris en compte même là où on n&#39;inclue pas debug_memory.h,</span>
<a name="l00127"></a>00127         <span class="comment">// mais pas la macro pour le new</span>
<a name="l00128"></a>00128         <span class="comment">// Dans ce cas on détruit le bloc et on quitte immédiatement</span>
<a name="l00129"></a>00129         free(ptr);
<a name="l00130"></a>00130         return ;
<a name="l00131"></a>00131     }
<a name="l00132"></a>00132 
<a name="l00133"></a>00133     <span class="comment">// Si le type d&#39;allocation (tableau / objet) ne correspond pas, on génère une erreur</span>
<a name="l00134"></a>00134     <span class="keywordflow">if</span>( <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].is_array != is_array )
<a name="l00135"></a>00135     {
<a name="l00136"></a>00136         <span class="keywordflow">if</span>( <a class="code" href="class_c_memory_manager.html#a66fa4e51f5c81fcf128365a217ffe46e" title="Pile contenant les infos sur les prochaines désallocations.">c_DeleteStack</a>.size() )
<a name="l00137"></a>00137             fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;&gt;&gt; Problème Tableau -- Désallocation   | 0x%08X | %15d octets | &lt;%15s&gt;:%u | ORG:&lt;%s&gt;:%u\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)ptr, <span class="keyword">static_cast&lt;</span><span class="keywordtype">int</span><span class="keyword">&gt;</span>(<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].size), <a class="code" href="class_c_memory_manager.html#a66fa4e51f5c81fcf128365a217ffe46e" title="Pile contenant les infos sur les prochaines désallocations.">c_DeleteStack</a>.top().fileName.c_str(), <a class="code" href="class_c_memory_manager.html#a66fa4e51f5c81fcf128365a217ffe46e" title="Pile contenant les infos sur les prochaines désallocations.">c_DeleteStack</a>.top().line, <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].fileName.c_str(), <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].line);
<a name="l00138"></a>00138         <span class="keywordflow">else</span>
<a name="l00139"></a>00139             fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;&gt;&gt; Problème Tableau -- Désallocation   | 0x%08X | %15d octets | &lt;%15s&gt;:%u\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)ptr, static_cast&lt;int&gt;(<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].size), <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].fileName.c_str(), <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].line);
<a name="l00140"></a>00140         return ;
<a name="l00141"></a>00141     }
<a name="l00142"></a>00142 
<a name="l00143"></a>00143 <span class="preprocessor">    #ifdef MEMORY_FULL_REPORT</span>
<a name="l00144"></a>00144 <span class="preprocessor"></span>        <span class="comment">// Finalement, si tout va bien, on supprime le bloc et on loggiz tout ça</span>
<a name="l00145"></a>00145         fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;-- Désallocation            | 0x%08X | %15d octets | &lt;%15s&gt;:%u | ORG:&lt;%s&gt;:%u\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)ptr, static_cast&lt;int&gt;(<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].size), <a class="code" href="class_c_memory_manager.html#a66fa4e51f5c81fcf128365a217ffe46e" title="Pile contenant les infos sur les prochaines désallocations.">c_DeleteStack</a>.top().fileName.c_str(), <a class="code" href="class_c_memory_manager.html#a66fa4e51f5c81fcf128365a217ffe46e" title="Pile contenant les infos sur les prochaines désallocations.">c_DeleteStack</a>.top().line, <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].fileName.c_str(), <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].line);
<a name="l00146"></a>00146 <span class="preprocessor">    #endif</span>
<a name="l00147"></a>00147 <span class="preprocessor"></span>    <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.erase(i+<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.begin());
<a name="l00148"></a>00148     <a class="code" href="class_c_memory_manager.html#a66fa4e51f5c81fcf128365a217ffe46e" title="Pile contenant les infos sur les prochaines désallocations.">c_DeleteStack</a>.pop();
<a name="l00149"></a>00149 
<a name="l00150"></a>00150     <span class="comment">// Libération de la mémoire</span>
<a name="l00151"></a>00151     free(ptr);
<a name="l00152"></a>00152 }
<a name="l00153"></a>00153 
<a name="l00154"></a>00154 
<a name="l00155"></a>00155 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00156"></a>00156 <span class="comment">* @fn void CMemoryManager::nextDelete( const char fileName[], unsigned int line )</span>
<a name="l00157"></a>00157 <span class="comment">* @brief Sauvegarde les infos sur la désallocation courante</span>
<a name="l00158"></a>00158 <span class="comment">*/</span>
<a name="l00159"></a><a class="code" href="class_c_memory_manager.html#ab70c6566b859092c13dcdbabafbea33e">00159</a> <span class="keywordtype">void</span> <a class="code" href="class_c_memory_manager.html#ab70c6566b859092c13dcdbabafbea33e" title="Sauvegarde les infos sur la désallocation courante.">CMemoryManager::nextDelete</a>( <span class="keyword">const</span> <span class="keywordtype">char</span> fileName[], <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> line )
<a name="l00160"></a>00160 {
<a name="l00161"></a>00161     <a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html" title="Stock les info sur les block mémoires alloués.">s_AllocatatedBlock</a> Delete;
<a name="l00162"></a>00162     Delete.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#a050ffa267c9f209f6a1159b6c2832142" title="Fichier contenant l&amp;#39;allocation.">fileName</a> = fileName;
<a name="l00163"></a>00163     Delete.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#a04a808fd7b875bb64b2e712c5da7968c" title="Ligne de l&amp;#39;allocation.">line</a> = line;
<a name="l00164"></a>00164 
<a name="l00165"></a>00165     <a class="code" href="class_c_memory_manager.html#a66fa4e51f5c81fcf128365a217ffe46e" title="Pile contenant les infos sur les prochaines désallocations.">c_DeleteStack</a>.push(Delete);
<a name="l00166"></a>00166 }
<a name="l00167"></a>00167 
<a name="l00168"></a>00168 
<a name="l00169"></a>00169 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00170"></a>00170 <span class="comment">* @fn CMemoryManager&amp; CMemoryManager::getInstance()</span>
<a name="l00171"></a>00171 <span class="comment">* @brief Renvoie l&#39;intance de la class</span>
<a name="l00172"></a>00172 <span class="comment">*/</span>
<a name="l00173"></a>00173 <span class="comment">// Renvoie l&#39;instance de la classe</span>
<a name="l00174"></a><a class="code" href="class_c_memory_manager.html#abd2c21f7bb412aa1f473e92ca029733d">00174</a> <a class="code" href="class_c_memory_manager.html" title="Système de vérification de fuite mémoire.">CMemoryManager</a>&amp; <a class="code" href="class_c_memory_manager.html#abd2c21f7bb412aa1f473e92ca029733d" title="Renvoie l&amp;#39;intance de la class.">CMemoryManager::getInstance</a>()
<a name="l00175"></a>00175 {
<a name="l00176"></a>00176     <span class="keywordflow">return</span> <a class="code" href="class_c_memory_manager.html#a48a8bd38d884d860ba2482b1cff0e135" title="L&amp;#39;instance de la class.">c_inst</a>;
<a name="l00177"></a>00177 }
<a name="l00178"></a>00178 
<a name="l00179"></a>00179 
<a name="l00180"></a>00180 <span class="comment">/*******************************************************************************</span>
<a name="l00181"></a>00181 <span class="comment">* Partie SDL</span>
<a name="l00182"></a>00182 <span class="comment">*/</span>
<a name="l00183"></a>00183 <span class="preprocessor">#ifdef __LIB_SDL__</span>
<a name="l00184"></a>00184 <span class="preprocessor"></span>    <span class="comment">// On vire les define</span>
<a name="l00185"></a>00185 <span class="preprocessor">    #undef IMG_Load</span>
<a name="l00186"></a>00186 <span class="preprocessor"></span><span class="preprocessor">    #undef SDL_FreeSurface</span>
<a name="l00187"></a>00187 <span class="preprocessor"></span><span class="preprocessor">    #undef TTF_RenderText_Blended</span>
<a name="l00188"></a>00188 <span class="preprocessor"></span><span class="preprocessor">    #undef TTF_OpenFont</span>
<a name="l00189"></a>00189 <span class="preprocessor"></span><span class="preprocessor">    #undef TTF_CloseFont</span>
<a name="l00190"></a>00190 <span class="preprocessor"></span>
<a name="l00191"></a>00191 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00192"></a>00192 <span class="comment">* @fn SDL_Surface* CMemoryManager::IMG_Load_Debug( const char img, const char fileName[], unsigned int line )</span>
<a name="l00193"></a>00193 <span class="comment">* @brief Récolte les informations sur les allocations des Surfaces SDL</span>
<a name="l00194"></a>00194 <span class="comment">*</span>
<a name="l00195"></a>00195 <span class="comment">* Permet grace aux surchages de compter et d&#39;identifier les allocations</span>
<a name="l00196"></a>00196 <span class="comment">*/</span>
<a name="l00197"></a><a class="code" href="class_c_memory_manager.html#a990328b78646a11ef3079a44e1b9115c">00197</a> SDL_Surface* <a class="code" href="class_c_memory_manager.html#a990328b78646a11ef3079a44e1b9115c">CMemoryManager::IMG_Load_Debug</a>( <span class="keyword">const</span> <span class="keywordtype">char</span> fileImg[], <span class="keyword">const</span> <span class="keywordtype">char</span> fileName[], <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> line )
<a name="l00198"></a>00198 {
<a name="l00199"></a>00199     <span class="comment">// Ajout du bloc à la liste des blocs alloués</span>
<a name="l00200"></a>00200     <a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html" title="Stock les info sur les block mémoires alloués.">s_AllocatatedBlock</a> newBlock;
<a name="l00201"></a>00201     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#afa806a065eca6cf997823dd160e6503c" title="Le pointeur.">ptr</a>        = (<span class="keywordtype">void</span>*)IMG_Load(fileImg);
<a name="l00202"></a>00202     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#a66687bce2aeeb39d1066c878e37136b0" title="Taille allouée.">size</a>       = 0;
<a name="l00203"></a>00203     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#a050ffa267c9f209f6a1159b6c2832142" title="Fichier contenant l&amp;#39;allocation.">fileName</a>   = fileName;
<a name="l00204"></a>00204     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#a04a808fd7b875bb64b2e712c5da7968c" title="Ligne de l&amp;#39;allocation.">line</a>       = line;
<a name="l00205"></a>00205     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#ad77e2f233ea15004acfd3206b00dc1dc" title="Type d&amp;#39;objet (SDL ou classic ?).">type</a>       = __SDL_Surface__;
<a name="l00206"></a>00206     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#ae08523066b3c9def225d38452557750f" title="Est-ce un objet ou un tableau ?">is_array</a>   = <span class="keyword">false</span>;
<a name="l00207"></a>00207     <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.push_back(newBlock);
<a name="l00208"></a>00208 
<a name="l00209"></a>00209 <span class="preprocessor">    #ifdef MEMORY_FULL_REPORT</span>
<a name="l00210"></a>00210 <span class="preprocessor"></span>        fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;++ Allocation Surface        | 0x%08X | %15c octets | &lt;%15s&gt;:%u\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#afa806a065eca6cf997823dd160e6503c" title="Le pointeur.">ptr</a>, <span class="charliteral">&#39;?&#39;</span>, fileName, line);
<a name="l00211"></a>00211 <span class="preprocessor">    #endif</span>
<a name="l00212"></a>00212 <span class="preprocessor"></span>
<a name="l00213"></a>00213     <span class="keywordflow">return</span> (SDL_Surface*)newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#afa806a065eca6cf997823dd160e6503c" title="Le pointeur.">ptr</a>;
<a name="l00214"></a>00214 }
<a name="l00215"></a>00215 
<a name="l00216"></a>00216 
<a name="l00217"></a>00217 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00218"></a>00218 <span class="comment">* @fn void CMemoryManager::SDL_FreeSurface_Debug( SDL_Surface* ptr, const char fileName[], unsigned int line )</span>
<a name="l00219"></a>00219 <span class="comment">* @brief Récolte les informations sur les désallocations des Surfaces SDL</span>
<a name="l00220"></a>00220 <span class="comment">*</span>
<a name="l00221"></a>00221 <span class="comment">* Permet grace aux surchages de compter et d&#39;identifier les désallocations.&lt;br /&gt;</span>
<a name="l00222"></a>00222 <span class="comment">* ( Retire une allocation mémoire )</span>
<a name="l00223"></a>00223 <span class="comment">*/</span>
<a name="l00224"></a><a class="code" href="class_c_memory_manager.html#a728395871f1562c6710b1c741af62a8a">00224</a> <span class="keywordtype">void</span> <a class="code" href="class_c_memory_manager.html#a728395871f1562c6710b1c741af62a8a" title="Récolte les informations sur les désallocations des Surfaces SDL.">CMemoryManager::SDL_FreeSurface_Debug</a>( SDL_Surface* ptr, <span class="keyword">const</span> <span class="keywordtype">char</span> fileName[], <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> line )
<a name="l00225"></a>00225 {
<a name="l00226"></a>00226     <span class="comment">// Recherche de l&#39;adresse dans les blocs alloués</span>
<a name="l00227"></a>00227     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0;
<a name="l00228"></a>00228     <span class="keywordflow">for</span>( i=0; i&lt;<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.size(); i++ )
<a name="l00229"></a>00229     {
<a name="l00230"></a>00230         <span class="keywordflow">if</span>( <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].ptr == (<span class="keywordtype">void</span>*)ptr ) <span class="keywordflow">break</span>;
<a name="l00231"></a>00231     }
<a name="l00232"></a>00232 
<a name="l00233"></a>00233     <span class="comment">// Si le bloc n&#39;a pas été alloué, on génère une erreur</span>
<a name="l00234"></a>00234     <span class="keywordflow">if</span>( <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.size() &lt;= i )
<a name="l00235"></a>00235     {
<a name="l00236"></a>00236         <span class="comment">// SDL_FreeSurface a été appelé mais la surface qui a été générée n&#39;est pas dans notre liste !</span>
<a name="l00237"></a>00237         <span class="comment">// Ce problème arrive souvent si la surface générée n&#39;est pas dans la liste des fonctions surchargées.</span>
<a name="l00238"></a>00238         <span class="comment">// Dans ce cas on détruit le bloc et on quitte immédiatement</span>
<a name="l00239"></a>00239         <span class="keyword">static</span> <span class="keywordtype">bool</span> signal = 1;<span class="comment">// Permet de signaler le problème une seul fois</span>
<a name="l00240"></a>00240         <span class="keywordflow">if</span>( signal ){
<a name="l00241"></a>00241             fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;Problème de désallocation d&#39;une surface (SDL) ! Pointeur(%u) non référencé &lt;%s&gt;:%u\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)ptr, fileName, line);
<a name="l00242"></a>00242             signal = 0;
<a name="l00243"></a>00243         }
<a name="l00244"></a>00244         SDL_FreeSurface(ptr);
<a name="l00245"></a>00245         return ;
<a name="l00246"></a>00246     }
<a name="l00247"></a>00247 
<a name="l00248"></a>00248 <span class="preprocessor">    #ifdef MEMORY_FULL_REPORT</span>
<a name="l00249"></a>00249 <span class="preprocessor"></span>        <span class="comment">// Finalement, si tout va bien, on supprime le bloc et on loggiz tout ça</span>
<a name="l00250"></a>00250         fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;-- Désallocation            | 0x%08X | %15c octets | &lt;%15s&gt;:%u | ORG:&lt;%s&gt;:%u\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)ptr, <span class="charliteral">&#39;?&#39;</span>, fileName, line, <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].fileName.c_str(), <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].line);
<a name="l00251"></a>00251 <span class="preprocessor">    #endif</span>
<a name="l00252"></a>00252 <span class="preprocessor"></span>    <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.erase(i+<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.begin());
<a name="l00253"></a>00253 
<a name="l00254"></a>00254     <span class="comment">// Libération de la mémoire</span>
<a name="l00255"></a>00255     SDL_FreeSurface(ptr);
<a name="l00256"></a>00256 }
<a name="l00257"></a>00257 
<a name="l00258"></a>00258 
<a name="l00259"></a>00259 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00260"></a>00260 <span class="comment">* @fn SDL_Surface* CMemoryManager::TTF_RenderText_Blended_Debug( TTF_Font *font, const char text[], SDL_Color color, const char fileName[], unsigned int line )</span>
<a name="l00261"></a>00261 <span class="comment">* @brief Récolte les informations sur les allocations des Surfaces SDL:TTF</span>
<a name="l00262"></a>00262 <span class="comment">*</span>
<a name="l00263"></a>00263 <span class="comment">* Permet grace aux surchages de compter et d&#39;identifier les allocations</span>
<a name="l00264"></a>00264 <span class="comment">*/</span>
<a name="l00265"></a><a class="code" href="class_c_memory_manager.html#ab57e5a6810861762c3c029be90b0da31">00265</a> SDL_Surface* <a class="code" href="class_c_memory_manager.html#ab57e5a6810861762c3c029be90b0da31" title="Récolte les informations sur les allocations des Surfaces SDL:TTF.">CMemoryManager::TTF_RenderText_Blended_Debug</a>( TTF_Font *font, <span class="keyword">const</span> <span class="keywordtype">char</span> text[], SDL_Color color, <span class="keyword">const</span> <span class="keywordtype">char</span> fileName[], <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> line )
<a name="l00266"></a>00266 {
<a name="l00267"></a>00267     <span class="comment">// Ajout du bloc à la liste des blocs alloués</span>
<a name="l00268"></a>00268     <a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html" title="Stock les info sur les block mémoires alloués.">s_AllocatatedBlock</a> newBlock;
<a name="l00269"></a>00269     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#afa806a065eca6cf997823dd160e6503c" title="Le pointeur.">ptr</a>        = (<span class="keywordtype">void</span>*)TTF_RenderText_Blended(font, text, color);
<a name="l00270"></a>00270     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#a66687bce2aeeb39d1066c878e37136b0" title="Taille allouée.">size</a>       = 0;
<a name="l00271"></a>00271     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#a050ffa267c9f209f6a1159b6c2832142" title="Fichier contenant l&amp;#39;allocation.">fileName</a>   = fileName;
<a name="l00272"></a>00272     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#a04a808fd7b875bb64b2e712c5da7968c" title="Ligne de l&amp;#39;allocation.">line</a>       = line;
<a name="l00273"></a>00273     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#ad77e2f233ea15004acfd3206b00dc1dc" title="Type d&amp;#39;objet (SDL ou classic ?).">type</a>       = __SDL_Surface__;
<a name="l00274"></a>00274     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#ae08523066b3c9def225d38452557750f" title="Est-ce un objet ou un tableau ?">is_array</a>   = <span class="keyword">false</span>;
<a name="l00275"></a>00275     <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.push_back(newBlock);
<a name="l00276"></a>00276 
<a name="l00277"></a>00277 <span class="preprocessor">    #ifdef MEMORY_FULL_REPORT</span>
<a name="l00278"></a>00278 <span class="preprocessor"></span>        fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;++ Allocation Surface text   | 0x%08X | %15c octets | &lt;%15s&gt;:%u\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#afa806a065eca6cf997823dd160e6503c" title="Le pointeur.">ptr</a>, <span class="charliteral">&#39;?&#39;</span>, fileName, line);
<a name="l00279"></a>00279 <span class="preprocessor">    #endif</span>
<a name="l00280"></a>00280 <span class="preprocessor"></span>
<a name="l00281"></a>00281     <span class="keywordflow">return</span> (SDL_Surface*)newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#afa806a065eca6cf997823dd160e6503c" title="Le pointeur.">ptr</a>;
<a name="l00282"></a>00282 }
<a name="l00283"></a>00283 
<a name="l00284"></a>00284 
<a name="l00285"></a>00285 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00286"></a>00286 <span class="comment">* @fn TTF_Font* CMemoryManager::TTF_OpenFont_Debug( const char file[], int size, const char fileName[], unsigned int line )</span>
<a name="l00287"></a>00287 <span class="comment">* @brief Récolte les informations sur les allocations des TTF_Font</span>
<a name="l00288"></a>00288 <span class="comment">*</span>
<a name="l00289"></a>00289 <span class="comment">* Permet grace aux surchages de compter et d&#39;identifier les allocations</span>
<a name="l00290"></a>00290 <span class="comment">*/</span>
<a name="l00291"></a><a class="code" href="class_c_memory_manager.html#ae0497df49ff60463727c867150d530c5">00291</a> TTF_Font* <a class="code" href="class_c_memory_manager.html#ae0497df49ff60463727c867150d530c5" title="Récolte les informations sur les allocations des TTF_Font.">CMemoryManager::TTF_OpenFont_Debug</a>( <span class="keyword">const</span> <span class="keywordtype">char</span> file[], <span class="keywordtype">int</span> size, <span class="keyword">const</span> <span class="keywordtype">char</span> fileName[], <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> line )
<a name="l00292"></a>00292 {
<a name="l00293"></a>00293     <span class="comment">// Ajout du bloc à la liste des blocs alloués</span>
<a name="l00294"></a>00294     <a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html" title="Stock les info sur les block mémoires alloués.">s_AllocatatedBlock</a> newBlock;
<a name="l00295"></a>00295     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#afa806a065eca6cf997823dd160e6503c" title="Le pointeur.">ptr</a>        = (<span class="keywordtype">void</span>*)TTF_OpenFont(file, size);
<a name="l00296"></a>00296     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#a66687bce2aeeb39d1066c878e37136b0" title="Taille allouée.">size</a>       = 0;
<a name="l00297"></a>00297     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#a050ffa267c9f209f6a1159b6c2832142" title="Fichier contenant l&amp;#39;allocation.">fileName</a>   = fileName;
<a name="l00298"></a>00298     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#a04a808fd7b875bb64b2e712c5da7968c" title="Ligne de l&amp;#39;allocation.">line</a>       = line;
<a name="l00299"></a>00299     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#ad77e2f233ea15004acfd3206b00dc1dc" title="Type d&amp;#39;objet (SDL ou classic ?).">type</a>       = __SDL_Font__;
<a name="l00300"></a>00300     newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#ae08523066b3c9def225d38452557750f" title="Est-ce un objet ou un tableau ?">is_array</a>   = <span class="keyword">false</span>;
<a name="l00301"></a>00301     <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.push_back(newBlock);
<a name="l00302"></a>00302 
<a name="l00303"></a>00303 <span class="preprocessor">    #ifdef MEMORY_FULL_REPORT</span>
<a name="l00304"></a>00304 <span class="preprocessor"></span>        fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;++ Allocation TTF            | 0x%08X | %15c octets | &lt;%15s&gt;:%u\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#afa806a065eca6cf997823dd160e6503c" title="Le pointeur.">ptr</a>, <span class="charliteral">&#39;?&#39;</span>, fileName, line);
<a name="l00305"></a>00305 <span class="preprocessor">    #endif</span>
<a name="l00306"></a>00306 <span class="preprocessor"></span>
<a name="l00307"></a>00307     <span class="keywordflow">return</span> (TTF_Font*)newBlock.<a class="code" href="struct_c_memory_manager_1_1s___allocatated_block.html#afa806a065eca6cf997823dd160e6503c" title="Le pointeur.">ptr</a>;
<a name="l00308"></a>00308 }
<a name="l00309"></a>00309 
<a name="l00310"></a>00310 
<a name="l00311"></a>00311 <span class="comment">/***************************************************************************/</span><span class="comment">/*!</span>
<a name="l00312"></a>00312 <span class="comment">* @fn void CMemoryManager::TTF_CloseFont_Debug( TTF_Font* ptr, const char fileName[], unsigned int line )</span>
<a name="l00313"></a>00313 <span class="comment">* @brief Récolte les informations sur les désallocations des TTF_Font</span>
<a name="l00314"></a>00314 <span class="comment">*</span>
<a name="l00315"></a>00315 <span class="comment">* Permet grace aux surchages de compter et d&#39;identifier les désallocations.&lt;br /&gt;</span>
<a name="l00316"></a>00316 <span class="comment">* ( Retire une allocation mémoire )</span>
<a name="l00317"></a>00317 <span class="comment">*/</span>
<a name="l00318"></a><a class="code" href="class_c_memory_manager.html#aa9445f0e6fe11a1933f7018b477554fd">00318</a> <span class="keywordtype">void</span> <a class="code" href="class_c_memory_manager.html#aa9445f0e6fe11a1933f7018b477554fd" title="Récolte les informations sur les désallocations des TTF_Font.">CMemoryManager::TTF_CloseFont_Debug</a>( TTF_Font* ptr, <span class="keyword">const</span> <span class="keywordtype">char</span> fileName[], <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> line )
<a name="l00319"></a>00319 {
<a name="l00320"></a>00320     <span class="comment">// Recherche de l&#39;adresse dans les blocs alloués</span>
<a name="l00321"></a>00321     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0;
<a name="l00322"></a>00322     <span class="keywordflow">for</span>( i=0; i&lt;<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.size(); i++ )
<a name="l00323"></a>00323     {
<a name="l00324"></a>00324         <span class="keywordflow">if</span>( <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].ptr == (<span class="keywordtype">void</span>*)ptr ) <span class="keywordflow">break</span>;
<a name="l00325"></a>00325     }
<a name="l00326"></a>00326 
<a name="l00327"></a>00327     <span class="comment">// Si le bloc n&#39;a pas été alloué, on génère une erreur</span>
<a name="l00328"></a>00328     <span class="keywordflow">if</span>( <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.size() &lt;= i )
<a name="l00329"></a>00329     {
<a name="l00330"></a>00330         <span class="comment">// TTF_CloseFont a été appelé mais la font qui a été générée n&#39;est pas dans notre liste !</span>
<a name="l00331"></a>00331         <span class="comment">// Ce problème arrive souvent si la font générée n&#39;est pas dans la liste des fonctions surchargées.</span>
<a name="l00332"></a>00332         fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;Problème de désallocation d&#39;un TTF (SDL) ! Pointeur(%u) non référencé &lt;%s&gt;:%u\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)ptr, fileName, line);
<a name="l00333"></a>00333         TTF_CloseFont(ptr);
<a name="l00334"></a>00334         return ;
<a name="l00335"></a>00335     }
<a name="l00336"></a>00336 
<a name="l00337"></a>00337 <span class="preprocessor">    #ifdef MEMORY_FULL_REPORT</span>
<a name="l00338"></a>00338 <span class="preprocessor"></span>        <span class="comment">// Finalement, si tout va bien, on supprime le bloc et on loggiz tout ça</span>
<a name="l00339"></a>00339         fprintf(<a class="code" href="class_c_memory_manager.html#ad8837a903dd88682e2c19a4d12d9168d" title="Pointeur de fichier où sera stocké le rapport.">c_fp</a>, <span class="stringliteral">&quot;-- Désallocation d&#39;un TTF   | 0x%08X | %15c octets | &lt;%15s&gt;:%u | ORG:&lt;%s&gt;:%u\n&quot;</span>, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)ptr, <span class="charliteral">&#39;?&#39;</span>, fileName, line, <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].fileName.c_str(), <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>[i].line);
<a name="l00340"></a>00340 <span class="preprocessor">    #endif</span>
<a name="l00341"></a>00341 <span class="preprocessor"></span>    <a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.erase(i+<a class="code" href="class_c_memory_manager.html#ab2d64d7c15f3b3d06cfa10d9e565c396" title="Blocs de mémoire alloués.">c_Blocks</a>.begin());
<a name="l00342"></a>00342 
<a name="l00343"></a>00343     <span class="comment">// Libération de la mémoire</span>
<a name="l00344"></a>00344     TTF_CloseFont(ptr);
<a name="l00345"></a>00345 }
<a name="l00346"></a>00346 <span class="preprocessor">#endif</span>
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Généré le Fri Jan 21 2011 01:21:27 pour Bomberman par&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.1 </small></address>
</body>
</html>
